import Peach from '@wattjs/peach'

export default defineNuxtRouteMiddleware((to, from) => {
  const { name, path, href, fullPath } = to
  // 记录页面访问日志
  if (process.client) {
    let host = window.location.origin + window.location.pathname
    host = host.replace(/([\w\W]+)\/$/, '$1')

    // 百度统计
    if (typeof _hmt !== 'undefined') {
      if (path) {
        _hmt.push(['_trackPageview', `${host}${href}`]);
      }
    }
    Peach.getInstance().logPage({ name, path: `${host}${href}`, fullPath })
  }
})
